package logic.common.missions;

import org.fenggui.util.Color;

import com.jme.math.Vector3f;

import fileHandling.language.LanguageLoader;
import fileHandling.language.interfaces.HUDText;
import logic.common.player.Player;
import logic.common.team.Team;
import map.spawnStation.SpawnStation;
import map.spawnStation.stationListeners.ConquerHelpedEvent;
import map.spawnStation.stationListeners.SpawnStationListener;
import map.spawnStation.stationListeners.StationConqueredEvent;

public class ConquerMission extends Mission {
	
	protected SpawnStation station;
	protected SpawnStationListener stationListener;
	
	public ConquerMission(Team team, int money, int assistMoney, SpawnStation station) {
		super(team, money, assistMoney);
		this.station = station;
		
		addSpawnStationListener();
	}
	
	protected void addSpawnStationListener() {
		final Mission thisMission = this;
		stationListener = new SpawnStationListener() {
			@Override
			public void conquered(StationConqueredEvent event) {
				Player conquerer = event.getConquerer();
				if(conquerer.getTeam() == team) missionAccomplished(conquerer);
				else team.deleteMission(thisMission);
				station.removeSpawnStationListener(stationListener);
			}
			
			@Override
			public void helpedConquer(ConquerHelpedEvent event) {
				Player helper = event.getConquerer();
				if(helper.getTeam() == team) {
					helper.assist(thisMission);
					station.removeSpawnStationListener(stationListener);
				}
			}
			
			@Override
			public void stationNeutralized() {}
		};
		station.addSpawnStationListener(stationListener);
	}
	
	@Override
	protected String getText() {
		String conquer = LanguageLoader.get(HUDText.Conquer);

		return conquer + " SpawnStation " + station.getStationLetter();
	}
	
	@Override
	public void missionActivated(boolean active, Player player) {
		super.missionActivated(active, player);
		if(player == team.getIngameState().getPlayer()) station.activateMissionAngles(active);
	}
	
	@Override
	public Vector3f getMissionLocation() { return station.getLocalTranslation(); }
	
	@Override
	public String[] getInfoTexts() {
		return new String[] { LanguageLoader.get(HUDText.SpawnStation_Conquered) };
	}
	
	@Override
	public Color[] getInfoColors() {
		return new Color[] { Color.WHITE };
	}
	
	@Override
	public String[] getAssistTexts() {
		return new String[] { LanguageLoader.get(HUDText.Conquer_Assist) };
	}
	
	@Override
	public Color[] getAssistColors() {
		return new Color[] { Color.WHITE };
	}
	
	@Override
	public boolean deleteAfterComplete() { return true; }
}